//@author A0097846J
package tasky.tests;

import static org.junit.Assert.*;

import java.awt.Color;

import org.junit.Test;

import tasky.ui.ColorGenerator;

/**
 * This is a Tester Class to test that the Color objects returned from the 
 * ColorGenerator class is correct.
 * 
 */


public class ColorGeneratorTest {

	//Class for testing
	ColorGenerator cg = new ColorGenerator();
	
	@Test
	public void colorTestForInt() {
		
		//Valid Colors
		Color testR = new Color(125, 5, 5);
		Color testB = new Color(5, 125, 5);
		Color testG = new Color(5, 5, 125);
		
		//Border Colors (Low : L and High : H)
		Color testRL = new Color(0, 5, 5);
		Color testBL = new Color(5, 0, 5);
		Color testGL = new Color(5, 5, 0);
		Color testRH = new Color(255, 5, 5);
		Color testBH = new Color(5, 255, 5);
		Color testGH = new Color(5, 5, 255);
		
		//Valid Errors
		String outBoundR = "The Value for Red is out of bounds! Please enter a value from 0 to 255\n";
		String outBoundB = "The Value for Blue is out of bounds! Please enter a value from 0 to 255\n";
		String outBoundG = "The Value for Green is out of bounds! Please enter a value from 0 to 255\n";
		
		try {
			
			/*	Heuristic: Combining Multiple Inputs
			 * 	Since there is 3 input values:	
			 *	There should be 3 non-contaminated Test Cases for each input
			 * 	There should only be 1 invalid input per Test Case
			 * 	*/
			
			/*	Test 1a: Test for a Red valid input 	*/
			assertEquals(testR, cg.generateColor(125, 5, 5));
			
			/*	Test 1b: Test for a Blue valid input	*/
			assertEquals(testB, cg.generateColor(5, 125, 5));
	
			/*	Test 1c: Test for a Green valid input	*/
			assertEquals(testG, cg.generateColor(5, 5, 125));

			/*	Heuristic: Equivalence Partitioning
			 * 	For each value (R,B,G): They have a range of 0 to 255
			 * 	We can separate them into 3 groups per value:
			 * 	1)	Negative Infinity ~ -1
			 * 	2)	0 ~ 255
			 * 	3)	256 ~ Infinity
			 * 
			 * 	Since 2) has been tested in Test 1, we test for 1) and 3)
			 */
			
			/*	Test 2a: Test Red's <0	Out of Range  */
			try {
				cg.generateColor(-1, 5, 5);
				fail();
			}catch(IllegalArgumentException e) {
				assertEquals(outBoundR, e.getMessage());
			}
			
			/*	Test 2b: Test Red's >255 Out of Range */
			try {
				cg.generateColor(256, 5, 5);
				fail();
			}catch(IllegalArgumentException e) {
				assertEquals(outBoundR, e.getMessage());
			}
			
			/*	Test 2c: Test Blue's <0	Out of Range  */
			try {
				cg.generateColor(5, -1, 5);
				fail();
			}catch(IllegalArgumentException e) {
				assertEquals(outBoundB, e.getMessage());
			}
			
			/*	Test 2d: Test Blue's >255 Out of Range */
			try {
				cg.generateColor(5, 256, 5);
				fail();
			}catch(IllegalArgumentException e) {
				assertEquals(outBoundB, e.getMessage());
			}
			
			/*	Test 2e: Test Green's <0 Out of Range  */
			try {
				cg.generateColor(5, 5, -1);
				fail();
			}catch(IllegalArgumentException e) {
				assertEquals(outBoundG, e.getMessage());
			}
			
			/*	Test 2f: Test Green's >255 Out of Range */
			try {
				cg.generateColor(5, 5, 256);
				fail();
			}catch(IllegalArgumentException e) {
				assertEquals(outBoundG, e.getMessage());
			}
			
			/*	Heuristic: Boundary Value Analysis
			 * 	For each value (R,B,G): They have a range of 0 to 255
			 * 	There exist Borders for the range, namely:
			 * 	1) -1
			 * 	2)	0
			 * 	3)	255
			 * 	4)	256
			 * 
			 * 	Since 1) and 4) have been tested, we test for 2) and 3)
			 */
			
			/*	Test 3a: Test for a Red Border input: 0 	*/
			assertEquals(testRL, cg.generateColor(0, 5, 5));
			
			/*	Test 3b: Test for a Red Border input: 255 	*/
			assertEquals(testRH, cg.generateColor(255, 5, 5));

			/*	Test 3c: Test for a Blue Border input: 0 	*/
			assertEquals(testBL, cg.generateColor(5, 0, 5));
			
			/*	Test 3d: Test for a Blue Border input: 255 	*/
			assertEquals(testBH, cg.generateColor(5, 255, 5));
		
			/*	Test 3e: Test for a Green Border input: 0 	*/
			assertEquals(testGL, cg.generateColor(5, 5, 0));
			
			/*	Test 3f: Test for a Green Border input: 255  */
			assertEquals(testGH, cg.generateColor(5, 5, 255));
			
		}catch(Exception e) {
			System.out.println("Error escaped Unit Test! Something has gone wrong!");
			e.printStackTrace();
			fail();
		}
	}
	
	
	@Test
	public void colorTestForString() {
		
		//Test Strings
		String wrongColor = "Color does not exist in program!\n";
		
		//In-built and custom Colors
		Color testDefaultRed = Color.RED;
		
		
		try {
			/*	Heuristic: Equivalence Partitioning / Combining Multiple Inputs
			 * 	Each result is based on a String input. Thus, we have:
			 * 	1)	Correct String input
			 * 	2)	Wrong String input
			 * 	3)	Wrong String input with Integer
			 * 	4)	Wrong String input with Symbol
			 *
			 *	Invalidity (String/Integer/Symbol) should not mix!
			 *
			*/
			
			/*	Test 1a: Test for a valid Color: Red 	*/
			assertEquals(testDefaultRed, cg.generateColor("RED"));
			
			/*	Test 1b: Test for an invalid Color: Wrong String */
			try {
				cg.generateColor("WRONG");
				fail();
			}catch(IllegalArgumentException e) {
				assertEquals(wrongColor, e.getMessage());
			}
			
			/*	Test 1c: Test for an invalid Color: Integers */
			try {
				cg.generateColor("WRONG");
				fail();
			}catch(IllegalArgumentException e) {
				assertEquals(wrongColor, e.getMessage());
			}
			
			/*	Test 1b: Test for an invalid Color: Symbols */
			try {
				cg.generateColor("!@#$%^&*_-.");
				fail();
			}catch(IllegalArgumentException e) {
				assertEquals(wrongColor, e.getMessage());
			}
			
		}catch(Exception e) {
			System.out.println("Error escaped Unit Test! Something has gone wrong!");
			e.printStackTrace();
			fail();
		}
	}

}
